package com.lnt.mq.rabbitmq.pubsub;

import com.lnt.mq.rabbitmq.util.RabbitConstant;
import com.lnt.mq.rabbitmq.util.RabbitUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 发布订阅模式
 * 一份数据多方共享
 * 适用于天气预报推送等一份数据分享给应用商这种广播性质工作场景
 * 这里扮演发布者的行为
 */
public class WeatherBureau {

    public static void main(String[] args) throws IOException, TimeoutException {

        String todayWeather = "晴天";
        Connection connection = RabbitUtil.getConnection();

        Channel channel = connection.createChannel();

        // param1: 交换机名称
        // param2: 队列名称
        //....
        channel.basicPublish(RabbitConstant.EXCHANGE_WEATHER, "", null, todayWeather.getBytes());

        channel.close();
        connection.close();
    }
}
